package org.changneng.framework.frameworkbusiness.controller;


import org.changneng.framework.frameworkbusiness.entity.Dept;
import org.changneng.framework.frameworkbusiness.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class DeptController {

    @Autowired
    private DeptService deptService;

    @RequestMapping("/insertDept")
    public String inset(Dept dept,Model model){
        System.out.println(dept.toString()+"----");
        int i = deptService.insert(dept);
        if (i>0){

            List<Dept> list = deptService.selectAll();
            model.addAttribute("list",list);
           return "deptList";
        }
        return "deptAdd";
    }

    @RequestMapping("/selectDept")
    public String selectDept(Model model){
        List<Dept> list = deptService.selectAll();
        model.addAttribute("list",list);
        return "deptList";
    }

    @RequestMapping("/deleteDept")
    public String deleteDept(int deptno){
        int i = deptService.delete(deptno);
        return "deptList";
    }

    @RequestMapping("/updateDept")
    public String updateDept(Dept dept){
        int i = deptService.update(dept);
        return "deptList";
    }
}
